package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateMenuLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 更新菜单信息
func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMenuLogic {
	return &UpdateMenuLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateMenuLogic) UpdateMenu(req *types.UpdateMenuRequest) error {
	_, err := l.svcCtx.AuthRoleRpc.UpdateMenu(l.ctx, &v1.UpdateMenuRequest{
		Id:           req.Id,
		MenuPid:      req.MenuPid,
		MenuName:     req.MenuName,
		MenuType:     v1.MenuType(req.MenuType),
		Target:       v1.MenuTarget(req.Target),
		Url:          req.Url,
		Icon:         req.Icon,
		Identifier:   req.Identifier,
		ListOrder:    req.ListOrder,
		Remark:       req.Remark,
		Visible:      v1.MenuVisible(req.Visible),
		Refresh:      v1.MenuRefresh(req.Refresh),
		Status:       v1.Status(req.Status),
		MenuLanguage: req.MenuLanguage,
	})

	return err
}
